<template>
	<eui-base-card :title="title" :titleLine="true">
		<eui-virtual-list :origList="pointsData" :options="options" type="list3" @itemClick="openDetail" />
	</eui-base-card>
</template>

<script setup lang="ts">
import { inject, ref, toRaw } from 'vue';

const title = ref('铺位');
const maxSort = ref(0);

const dataList = ref([
	// { name: '', status: '', statusColor: '' },
]);

const pointsData = inject('patrolWorkbenchPointsData', dataList);
const itemData = inject('patrolWorkbenchItemsData');
const resultsData = inject('patrolWorkbenchResultsData');

const options = ref({
	leftParam: 'c_point_id',
	centerParam: 'status',
	rightParam: 'abnormal',
	rightParamColor: 'statusColor'
});

const openDetail = (data: any) => {
	console.log('data', data);
	const pointId = data.item.c_point_id;
	maxSort.value = resultsData?.value?.length > 0 ? resultsData?.value?.reduce((a, b) => a.c_sort > b.c_sort ? a : b).c_sort : 1;
	const pointResultData = resultsData?.value.filter(t => t.c_point_id == pointId);
	const pointData = itemData?.value.datas.map(t => {
		const curPointItem = pointResultData?.find(r => r.c_item_id == t.c_item_id);
		return {
			...t,
			c_option_list: t.c_option_list.map(item => {
				return {
					...item,
					checked: curPointItem?.c_value?.includes(item.value) ? true : false
				}
			}),
			c_is_abnormal: curPointItem?.c_is_abnormal == '1' ? true : false,
			c_is_rectify: curPointItem?.c_is_rectify == '1' ? true : false,
			c_is_recheck: curPointItem?.c_is_recheck == '1' ? true : false,
			c_rectify_userno: curPointItem?.c_rectify_userno || '',
			c_rectify_provider: curPointItem?.c_rectify_provider || '',
			c_deadline: curPointItem?.c_deadline || '',
			c_sort: curPointItem?.c_sort || 0,
			c_value: curPointItem?.c_value || '',
			c_recheck_memo: curPointItem?.c_recheck_memo || '',
			c_rectify_memo: curPointItem?.c_rectify_memo || '',
			c_penalty: curPointItem?.c_penalty || 0,
			// c_work_status: 0：待确认 1：待处理 2：已作废 3：待评价 4：已完成 5：待整改 6：已整改 7：复检完成 9：已驳回
			c_displayable: '2,3,4,5,6,7'.includes(data.item.c_work_status) ? true : false,
			c_work_status: data.item.c_work_status
		}
	})
	console.log('pointData', pointData);
	const theme = itemData?.value.title;

	uni.navigateTo({ url: `./pointDetail?id=${data.item.c_id}&pointId=${data.item.c_point_id}&maxSort=${maxSort.value}&theme=${encodeURIComponent(theme)}&data=${encodeURIComponent(JSON.stringify(toRaw(pointData)))}` });
}

</script>

<style lang="scss" scoped></style>